#ifndef BCH_H
#define BCH_H

#include <vector>

namespace qrcode{

class BCH
{
private:
    std::vector<int> generatorPolyBits15_5;
    std::vector<int> generatorPolyBits18_6;
    int generator15_5;
    int generator18_6;

    void AddEnd0s(std::vector<int> &vec, int length);
    void AddBegin0s(std::vector<int> &vec, int length);
    void RemodeLeft0s(std::vector<int> &vec);
    bool IsNot0s(std::vector<int> &vec);
    void XOR(std::vector<int> &vec, std::vector<int> &vec1);

    //使用移位运算进行编码和解码
    int CodeFormat(int fmt);
    int CodeVersion(int ver);
    int DecodeFormat(int fmt);
    int DecodeVersion(int ver);
    int HammingWeight(int x);

    int VecToInt(std::vector<int> &vec);

    //译码
    bool IsCorrect(std::vector<int> &vec, std::vector<int> vec1);

public:
    BCH();
    std::vector<int> Encoding15_5(std::vector<int> format);
    std::vector<int> Encoding18_6(std::vector<int> format);

    std::vector<int> Decoding15_5(std::vector<int> format);
    std::vector<int> Decoding18_6(std::vector<int> ver);

    bool IsCorrect15_5(std::vector<int> vec);
    bool IsCorrect18_6(std::vector<int> vec);
};

}

#endif // BCH_H
